<?php
require_once('security.php');
 

  if (isset($_POST['submit']) && strlen(trim($_POST['delete']))>0) { // Handle the form

	$okflag=0; // Count each deleted file
    // Specify the .php file
    $phpfile = '../' .trim($_POST['delete']) .'.php';
    // Specify the .txt file
    $txtfile = '../textfiles/' . $_POST['delete'] . '.txt';

    // Check for existence of files
    // php file
    if (file_exists($phpfile)) {
      unlink($phpfile);
      $response1 = 'Success. <b>' . $_POST['delete'] . '.php</b> was deleted.<br />';
      $okflag+=1;
	  
    } else {
      $response1 = 'Sorry, <b>' . $_POST['delete'] . '.php</b> does not exist. Try another.<br />';
    }

    // txt file
    if (file_exists($txtfile)) {
      unlink($txtfile);
      $response2 = 'Success. <b>' . $_POST['delete'] . '.txt</b> was deleted.<br />';
      $okflag+=1;
    } else {
      $response2 = 'Sorry, <b>' . $_POST['delete'] . '.txt</b> does not exist. Try another.<br />';
    }
	if ($okflag > 0){
		include('delmenu.php');
		global $t;
		$delfile= "../categories/" .trim($_POST['delete']);
		if (file_exists($delfile)){
			$error= system("rm -f " .$delfile ." 2>&1");
			$response = 'The ' .$t .' Link to file: <b>' .$_POST['delete'] . '.php</b> has been deleted from the menu.<br />';
			if (strlen($error) == 0){
				$response = $response ."Image category file: " .$delfile ." deleted.<br />";
			}else{
				$response = $response ."Error deleting file: " .$delfile ." " .$error ."<br />";
			}
		}else{
			$response = 'The ' .$t .' Link to file: <b>' .$_POST['delete'] . '.php</b> has been deleted from the menu.<br />';
		} 
	}

  }

?>

<?php $thisPage = "delete"; ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Delete a page</title>
<meta name="robots" content="noindex,nofollow" />
<?php require_once('theme/admintheme.php');?>
</head>
<body>

<div id="wrap">



<?php include_once('navigation.php'); ?>

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
Name of page to be deleted (eg mypage)<br />
<input type="text" name="delete" id="delete" size="40" value="<?php if (isset($_POST['submit'])) echo $_POST['delete']; ?>" maxlength="60" />
<br />
<input type="submit" name="submit" value="Delete page" />
</form>

<?php if (isset($response1) && isset($response2)) {echo $response1 . $response2;} ?>
<?php if (isset($response)) {echo $response;} ?>

<?php include_once('list-all.php'); unset($_POST); ?>

<div style="clear: both;"></div>
</div>

</body>
</html>
